<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/blog/","images":"/blog/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta property="og:type" content="website">
<meta property="og:title" content="一年春又来">
<meta property="og:url" content="http://littlefxc.github.io/page/13/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="一年春又来">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://littlefxc.github.io/page/13/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>
<title>一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/blog/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/blog/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/blog/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/blog/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/blog/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">184</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2020/03/03/%E5%85%B6%E4%BB%96%E4%BA%BA%E7%9A%84%E7%9F%A5%E8%AF%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2020/03/03/%E5%85%B6%E4%BB%96%E4%BA%BA%E7%9A%84%E7%9F%A5%E8%AF%86/" class="post-title-link" itemprop="url">其他人的知识</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-03-03 08:39:54" itemprop="dateCreated datePublished" datetime="2020-03-03T08:39:54+08:00">2020-03-03</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/41d359a6aaee">jmeter进行http压力测试（图文小教程）</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/imyalost/p/9808079.html">jmeter（二十五）linux环境运行jmeter并生成报告</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/imyalost/p/10239317.html">jmeter（二十六）生成HTML性能测试报告</a></p>
<h2 id="RocketMQ"><a href="#RocketMQ" class="headerlink" title="RocketMQ"></a>RocketMQ</h2><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/qdhxhz/p/11096682.html">RocketMQ(2)—Docker部署RocketMQ集群</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/fx-blog/p/11738419.html">Spring Cloud Alibaba学习笔记（11） - RocketMQ事务消息</a></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2020/02/28/RocketMQ/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2020/02/28/RocketMQ/" class="post-title-link" itemprop="url">RocketMQ</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-02-28 14:35:32" itemprop="dateCreated datePublished" datetime="2020-02-28T14:35:32+08:00">2020-02-28</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:48" itemprop="dateModified" datetime="2021-03-25T21:15:48+08:00">2021-03-25</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="参考资源"><a href="#参考资源" class="headerlink" title="参考资源"></a>参考资源</h2><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/qdhxhz/p/11096682.html">RocketMQ(2)—Docker部署RocketMQ集群</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/fx-blog/p/11738419.html">Spring Cloud Alibaba学习笔记（11） - RocketMQ事务消息</a></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2020/02/26/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90-SpringBoot%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90%E5%8E%9F%E7%90%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2020/02/26/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90-SpringBoot%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90%E5%8E%9F%E7%90%86/" class="post-title-link" itemprop="url">源码分析:SpringBoot启动流程分析原理</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-02-26 20:51:54" itemprop="dateCreated datePublished" datetime="2020-02-26T20:51:54+08:00">2020-02-26</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <blockquote>
<p>我们都知道SpringBoot自问世以来，一直有一个响亮的口号”约定优于配置”，其实一种按约定编程的软件设计范式，目的在于减少软件开发人员在工作中的各种繁琐的配置，我们都知道传统的SSM框架的组合，会伴随着大量的繁琐的配置；稍有不慎，就可能各种bug，被人发现还以为我们技术很菜。而SpringBoot的出现不仅大大提高的开发人员的效率，还能避免由于”手抖”带来的配置错误。</p>
</blockquote>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2020/02/26/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90-SpringBoot%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90%E5%8E%9F%E7%90%86/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/11/27/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E4%B8%8E%E9%AD%94%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/11/27/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E4%B8%8E%E9%AD%94%E6%95%B0/" class="post-title-link" itemprop="url">文件上传与魔数</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-27 10:19:25" itemprop="dateCreated datePublished" datetime="2019-11-27T10:19:25+08:00">2019-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="问题的出现"><a href="#问题的出现" class="headerlink" title="问题的出现"></a>问题的出现</h2><p>今天在测试图片上传的时候，工作电脑中没有现成的图片（其实是懒得找），又不想去网上下载就把word文档改了后缀名(.jpeg)上传，没想到上传失败。</p>
<p>心里头非常纳闷，第一反应是代码有BUG，打开项目的过程中，不对。我把文件后缀名重新改回在上传文件，可以正常上传了。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2019/11/27/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E4%B8%8E%E9%AD%94%E6%95%B0/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/11/27/Elasticsearch-%E5%AE%89%E5%85%A8%E5%8A%9F%E8%83%BD%E5%85%A5%E9%97%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/11/27/Elasticsearch-%E5%AE%89%E5%85%A8%E5%8A%9F%E8%83%BD%E5%85%A5%E9%97%A8/" class="post-title-link" itemprop="url">Elasticsearch 安全功能入门</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-27 09:46:37" itemprop="dateCreated datePublished" datetime="2019-11-27T09:46:37+08:00">2019-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:48" itemprop="dateModified" datetime="2021-03-25T21:15:48+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/ELK/" itemprop="url" rel="index"><span itemprop="name">ELK</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="1-前言"><a href="#1-前言" class="headerlink" title="1. 前言"></a>1. 前言</h1><p>**<a target="_blank" rel="noopener" href="https://www.elastic.co/cn/blog/security-for-elasticsearch-is-now-free">从 Elastic Stack 6.8 和 7.1 开始</a><strong>，Elasticsearch在默认分发包中免费提供多项安全功能，例如 <strong>TLS 加密通信</strong>、</strong>基于角色的访问控制 (RBAC)**，等等。在本文中，我将会演示如何启用这些功能来确保您的 Elasticsearch 集群的安全。</p>
<p>实际演示中，我将会在两台centos7上各自创建一个一节点 Elasticsearch 集群并进行安全设置。要实现这一点，我们首先需要在两个节点之间配置 TLS 通信。然后，我会为 Kibana 实例启用安全功能。再然后，我会在 Kibana 中配置基于角色的访问控制，从而确保用户只能看到他们获授权能够看到的内容。</p>
<p>尽管关于安全功能的运行过程还有很多内容，但现在我们仅会介绍入门所需知识。</p>
<h1 id="2-安装-Elasticsearch-和-Kibana"><a href="#2-安装-Elasticsearch-和-Kibana" class="headerlink" title="2. 安装 Elasticsearch 和 Kibana"></a>2. 安装 Elasticsearch 和 Kibana</h1><p>略</p>
<h1 id="3-传输层配置-TLS-和身份验证"><a href="#3-传输层配置-TLS-和身份验证" class="headerlink" title="3. 传输层配置 TLS 和身份验证"></a>3. 传输层配置 TLS 和身份验证</h1><h2 id="3-1-在-Elasticsearch-主节点上配置-TLS"><a href="#3-1-在-Elasticsearch-主节点上配置-TLS" class="headerlink" title="3.1. 在 Elasticsearch 主节点上配置 TLS"></a>3.1. 在 Elasticsearch 主节点上配置 TLS</h2><p>我要做的第一件事是生成证书，通过这些证书便能允许节点安全地通信。您可以使用企业 CA 来完成这一步骤，但是在此演示中，我将会使用一个名为 elasticsearch-certutil 的命令，通过这一命令，就无需担心证书通常带来的任何困扰，便能完成这一步。</p>
<pre><code>bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass &quot;&quot;
</code></pre>
<p>如果您使用密码保护了节点证书的安全，请将密码添加到您的Elasticsearch密钥库中：</p>
<pre><code>bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass &quot;testpassword&quot;

bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password

bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
</code></pre>
<p>接下来，使用您最常用的文本编辑器打开文件 <code>config/elasticsearch.yaml</code>。将下列代码行粘贴到文件末尾。</p>
<pre><code>xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
</code></pre>
<p>保存文件，现在我们便可以启动主节点了。运行命令 bin/elasticsearch。这一可执行文件必须保持运行，现在可以将此终端放在一边。</p>
<h2 id="3-2-Elasticsearch-集群密码"><a href="#3-2-Elasticsearch-集群密码" class="headerlink" title="3.2. Elasticsearch 集群密码"></a>3.2. Elasticsearch 集群密码</h2><p><a target="_blank" rel="noopener" href="https://www.elastic.co/guide/en/elasticsearch/reference/7.1/setup-passwords.html"><code>elasticsearch-setup-passwords</code> 官方文档</a></p>
<p>注意：<code>elasticsearch-setup-passwords</code> 这个命令只能使用一次。</p>
<pre><code># 生成随机密码
bin/elasticsearch-setup-passwords auto

# 手动定义密码（建议使用）
bin/elasticsearch-setup-passwords interactive
</code></pre>
<p>但是如果完全忘记了 Elasticsearch 的超级用户的密码，请看</p>
<p><a target="_blank" rel="noopener" href="https://www.notion.so/a9cab5834874407681edc7b573730e0d">Elasticsearch 7.1 重置超级用户的密码</a></p>
<h2 id="3-3-在从节点上配置-TLS"><a href="#3-3-在从节点上配置-TLS" class="headerlink" title="3.3. 在从节点上配置 TLS"></a>3.3. 在从节点上配置 TLS</h2><p>复制证书文件，然后将 <strong>xpack.security.</strong>* 键设置为与主节点一模一样。然后通过运行 <code>bin/elasticsearch</code> 来启动节点。我们将看到其加入集群。而且，如果看一下主节点的终端窗口，我们会看到有一条消息显示已有一个节点加入集群。现在，我们的两节点集群便开始运行了。</p>
<h2 id="3-4-在-Kibana-中实现安全性"><a href="#3-4-在-Kibana-中实现安全性" class="headerlink" title="3.4. 在 Kibana 中实现安全性"></a>3.4. 在 Kibana 中实现安全性</h2><p>在 <code>kibana</code> 安装目录中编辑 <code>config/kibana.yml</code>到类似下面的代码行</p>
<pre><code>#elasticsearch.username: &quot;kibana&quot;
#elasticsearch.password: &quot;testpassword&quot;
</code></pre>
<p>对 <code>username</code> 和 <code>password</code> 字段取消注释，方法是删除代码行起始部分的 <code>#</code> 符号。将 “user” 更改为 “kibana”，然后将 “pass” 更改为 <code>setup-passwords</code> 命令告诉我们的任何 Kibana 密码。保存文件，然后我们便可通过运行 bin/kibana 启动 Kibana 了。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/11/27/ElasticSearch-%E5%AE%89%E8%A3%85%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D%E6%8F%92%E4%BB%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/11/27/ElasticSearch-%E5%AE%89%E8%A3%85%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D%E6%8F%92%E4%BB%B6/" class="post-title-link" itemprop="url">ElasticSearch 安装中文分词插件</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-27 09:45:05" itemprop="dateCreated datePublished" datetime="2019-11-27T09:45:05+08:00">2019-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:48" itemprop="dateModified" datetime="2021-03-25T21:15:48+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/ELK/" itemprop="url" rel="index"><span itemprop="name">ELK</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="1-安装-Elasticsearch"><a href="#1-安装-Elasticsearch" class="headerlink" title="1. 安装 Elasticsearch"></a>1. 安装 Elasticsearch</h1><p>略</p>
<h1 id="2-安装IK分词器插件"><a href="#2-安装IK分词器插件" class="headerlink" title="2. 安装IK分词器插件"></a>2. 安装IK分词器插件</h1><p>进入 Elasticsearch 安装目录</p>
<p>使用 <code>elasticsearch-plugin</code> 安装插件</p>
<pre><code>./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip
</code></pre>
<p>安装步骤截图如下</p>
<p><img src="https://img-blog.csdnimg.cn/20191105170349939.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p><strong>Tips</strong>: 如果是集群，则每个 es 节点都要安装该插件</p>
<h1 id="3-确认安装插件成功"><a href="#3-确认安装插件成功" class="headerlink" title="3. 确认安装插件成功"></a>3. 确认安装插件成功</h1><pre><code>./bin/elasticsearch-plugin list
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/20191105170358335.png" alt="在这里插入图片描述"></p>
<h1 id="4-移除插件"><a href="#4-移除插件" class="headerlink" title="4. 移除插件"></a>4. 移除插件</h1><pre><code>./bin/elasticsearch-plugin remove analysis-ik
</code></pre>
<h1 id="5-自定义中文词库"><a href="#5-自定义中文词库" class="headerlink" title="5. 自定义中文词库"></a>5. 自定义中文词库</h1><h2 id="5-1-在-es-plugins-ik-config下，创建："><a href="#5-1-在-es-plugins-ik-config下，创建：" class="headerlink" title="5.1. 在{es}/plugins/ik/config下，创建："></a>5.1. 在{es}/plugins/ik/config下，创建：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim custom.dic</span><br></pre></td></tr></table></figure>

<h2 id="5-2-并且添加内容："><a href="#5-2-并且添加内容：" class="headerlink" title="5.2. 并且添加内容："></a>5.2. 并且添加内容：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">雨女无瓜</span><br><span class="line">骚年</span><br></pre></td></tr></table></figure>

<h2 id="5-3-配置自定义扩展词典"><a href="#5-3-配置自定义扩展词典" class="headerlink" title="5.3.配置自定义扩展词典"></a>5.3.配置自定义扩展词典</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;entry key=<span class="string">&quot;ext_dict&quot;</span>&gt;custom.dic&lt;/entry&gt;</span><br></pre></td></tr></table></figure>

<h2 id="5-4-重启"><a href="#5-4-重启" class="headerlink" title="5.4. 重启"></a>5.4. 重启</h2>
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/11/27/Spring-boot-%E4%B8%AD-Scheduled-%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%E7%9A%84%E4%B8%80%E4%B8%AA%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/11/27/Spring-boot-%E4%B8%AD-Scheduled-%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%E7%9A%84%E4%B8%80%E4%B8%AA%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/" class="post-title-link" itemprop="url">Spring boot 中 @Scheduled 不起作用的一个解决办法</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-27 09:42:47" itemprop="dateCreated datePublished" datetime="2019-11-27T09:42:47+08:00">2019-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/springboot/" itemprop="url" rel="index"><span itemprop="name">springboot</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="Spring-boot-中-Scheduled-不起作用的一个解决办法"><a href="#Spring-boot-中-Scheduled-不起作用的一个解决办法" class="headerlink" title="Spring boot 中 @Scheduled 不起作用的一个解决办法"></a>Spring boot 中 @Scheduled 不起作用的一个解决办法</h1><p>在 spring boot 应用中添加定时任务，按照网上的资料却怎么都不能启动，都说是缺少了 <code>@EnableScheduling</code>,我在加上了后却任然启动不了。</p>
<p>最后是这样解决的：主要是新增一个 <code>org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler</code>  的 bean</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@EnableScheduling</span></span><br><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Sched</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> StatisticProperties statisticProperties;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> JedisCluster jedisCluster;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> TaskScheduler <span class="title">poolScheduler</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        ThreadPoolTaskScheduler scheduler = <span class="keyword">new</span> ThreadPoolTaskScheduler();</span><br><span class="line">        scheduler.setThreadNamePrefix(<span class="string">&quot;poolScheduler&quot;</span>);</span><br><span class="line">        scheduler.setPoolSize(<span class="number">10</span>);</span><br><span class="line">        <span class="keyword">return</span> scheduler;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Async(value = &quot;asyncPoolTaskExecutor&quot;)</span></span><br><span class="line">    <span class="meta">@Scheduled(cron = &quot;*/5 * * * * ?&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">clearRealtimeCacheData</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        log.info(<span class="string">&quot;每5秒执行一次&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/11/27/cron%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%B8%B8%E7%94%A8%E4%BE%8B%E5%AD%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/11/27/cron%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%B8%B8%E7%94%A8%E4%BE%8B%E5%AD%90/" class="post-title-link" itemprop="url">cron表达式常用例子</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-27 09:38:13" itemprop="dateCreated datePublished" datetime="2019-11-27T09:38:13+08:00">2019-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/spring/" itemprop="url" rel="index"><span itemprop="name">spring</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="cron表达式常用例子"><a href="#cron表达式常用例子" class="headerlink" title="cron表达式常用例子"></a>cron表达式常用例子</h1><p>cron 表达式的写法老是记不住，当然也是我根本不想记得原因所致。</p>
<p>这里记录一下，有用到就来看一下</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2019/11/27/cron%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%B8%B8%E7%94%A8%E4%BE%8B%E5%AD%90/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/10/08/Mysql%E4%B8%AD%E6%97%A5%E6%9C%9F%E6%AF%94%E8%BE%83%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%96%B9%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/10/08/Mysql%E4%B8%AD%E6%97%A5%E6%9C%9F%E6%AF%94%E8%BE%83%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%96%B9%E6%B3%95/" class="post-title-link" itemprop="url">Mysql中日期比较大小的方法</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-10-08 18:18:15" itemprop="dateCreated datePublished" datetime="2019-10-08T18:18:15+08:00">2019-10-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:48" itemprop="dateModified" datetime="2021-03-25T21:15:48+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/RDBMS/" itemprop="url" rel="index"><span itemprop="name">RDBMS</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>假如有个表<code>commodity</code>有个字段add_time,它的数据类型为datetime,有人可能会这样写sql：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> product <span class="keyword">where</span> add_time <span class="operator">=</span> <span class="string">&#x27;2013-01-12&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p>这种语句，如果你存储的格式是YY-mm-dd这样，那么OK，<br>如果你存储的格式是：2018-01-12 23:23:56 这种就悲剧了，此时你可以用 DATE() 函数用来返回日期的部分；sql如下处理：</p>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> product <span class="keyword">where</span> <span class="type">Date</span>(add_time) <span class="operator">=</span> <span class="string">&#x27;2018-01-12&#x27;</span></span><br></pre></td></tr></table></figure>

<ol>
<li>如果你要查询2017年1月份加入的产品呢？</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> product <span class="keyword">where</span> <span class="type">date</span>(add_time) <span class="keyword">between</span> <span class="string">&#x27;2013-01-01&#x27;</span> <span class="keyword">and</span> <span class="string">&#x27;2013-01-31&#x27;</span></span><br></pre></td></tr></table></figure>

<p>  或者： 还可以这样写：</p>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> product <span class="keyword">where</span> <span class="keyword">Year</span>(add_time) <span class="operator">=</span> <span class="number">2013</span> <span class="keyword">and</span> <span class="keyword">Month</span>(add_time) <span class="operator">=</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>其date_col的值是在最后30天以内：</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> commodity  <span class="keyword">WHERE</span> TO_DAYS( NOW() ) <span class="operator">-</span> TO_DAYS( date_col )  <span class="operator">&lt;=</span> <span class="number">30</span>;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>DAYOFWEEK(date) ： 返回日期date的星期索引(1=星期天, 7=星期六) 这些索引值对应于ODBC标准。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DAYOFWEEK(<span class="string">&#x27;1998-02-03&#x27;</span>);                     <span class="operator">-</span><span class="operator">&gt;</span>  <span class="number">3</span></span><br></pre></td></tr></table></figure>

<ol start="4">
<li>WEEKDAY(date)  ： 返回date的星期索引 (0=星期一, 6= 星期天)</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> WEEKDAY(<span class="string">&#x27;1997-10-04 22:23:00&#x27;</span>);             <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">5</span></span><br><span class="line"><span class="keyword">select</span> WEEKDAY(<span class="string">&#x27;2018-07-07&#x27;</span>);                      <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">5</span></span><br></pre></td></tr></table></figure>

<ol start="5">
<li>DAYOFMONTH(date) ：  返回date的月份中日期，在1到31范围内。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DAYOFMONTH(<span class="string">&#x27;1998-02-03&#x27;</span>);                    <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">3</span></span><br></pre></td></tr></table></figure>

<ol start="6">
<li>DAYOFYEAR(date) ：  返回date在一年中的日数, 在1到366范围内。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DAYOFYEAR(<span class="string">&#x27;1998-02-03&#x27;</span>);                     <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">34</span></span><br></pre></td></tr></table></figure>

<ol start="7">
<li>MONTH(date) ：   返回date的月份，范围1到12。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">MONTH</span>(<span class="string">&#x27;1998-02-03&#x27;</span>);                         <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">2</span></span><br></pre></td></tr></table></figure>

<ol start="8">
<li>DAYNAME(date) ： 返回date的星期名字。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DAYNAME(&quot;1998-02-05&quot;);                       <span class="operator">-</span><span class="operator">&gt;</span> <span class="string">&#x27;Thursday&#x27;</span></span><br><span class="line"><span class="keyword">select</span> DAYNAME(&quot;20180707&quot;);                         <span class="operator">-</span><span class="operator">&gt;</span> <span class="string">&#x27;Saturday&#x27;</span></span><br></pre></td></tr></table></figure>

<ol>
<li>MONTHNAME(date) ： 返回date的月份名字。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> MONTHNAME(&quot;1998-02-05&quot;);                     <span class="operator">-</span><span class="operator">&gt;</span> <span class="string">&#x27;February&#x27;</span></span><br></pre></td></tr></table></figure>

<ol start="10">
<li>QUARTER(date)  ： 返回date一年中的季度，范围1到4。</li>
</ol>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> QUARTER(<span class="string">&#x27;98-04-01&#x27;</span>);                          <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">2</span></span><br><span class="line"><span class="keyword">select</span> QUARTER(<span class="string">&#x27;20180707&#x27;</span>);                          <span class="operator">-</span><span class="operator">&gt;</span> <span class="number">3</span></span><br></pre></td></tr></table></figure>

<p>这是做统计数据时候用了的sql.</p>
<p>查询今天、昨天、一周内、8周、12周等数据 直接在sql写时间查询。 避免时区转化。数据库我们使用的UTC时间。</p>
<ul>
<li><p>Today</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> todayBegin;</span><br><span class="line"><span class="keyword">SELECT</span> date_add(date_add(str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">interval</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>) <span class="keyword">as</span> todayEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>昨天</p>
<p>``sql<br>SELECT str_to_date(date_sub(curdate(), interval 1 day),’%Y-%m-%d %H:%i:%s’) as yestodayBegin;<br>SELECT date_add(date_add(str_to_date(date_sub(curdate(), interval 1 day),’%Y-%m-%d %H:%i:%s’),interval 1 DAY),INTERVAL -1 SECOND) as yestodayEnd;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">- 最近7天 Last Seven days</span><br><span class="line"></span><br><span class="line">  &#96;&#96;&#96;sql</span><br><span class="line">  SELECT str_to_date(date_sub(curdate(), interval 6 day),&#39;%Y-%m-%d %H:%i:%s&#39;) as lastSevenDaysBegin;</span><br><span class="line">  SELECT date_add(date_add(str_to_date(curdate(),&#39;%Y-%m-%d %H:%i:%s&#39;),interval 1 DAY),INTERVAL -1 SECOND) as todayEnd;</span><br></pre></td></tr></table></figure>
</li>
<li><p>最近14天 Last Fourteen days</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(date_sub(curdate(), <span class="type">interval</span> <span class="number">13</span> <span class="keyword">day</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> lastFourteenDaysBegin;</span><br><span class="line"><span class="keyword">SELECT</span> date_add(date_add(str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">interval</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>) <span class="keyword">as</span> todayEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>最近30天 Last Thirty days</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(date_sub(curdate(), <span class="type">interval</span> <span class="number">29</span> <span class="keyword">day</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> lastThirtyDaysBegin;</span><br><span class="line"><span class="keyword">SELECT</span> date_add(date_add(str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">interval</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>) <span class="keyword">as</span> todayEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>最近8周 Last eight weeks</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(date_sub(curdate(), <span class="type">interval</span> <span class="number">8</span> week),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> lastEightWeeksBegin;</span><br><span class="line"><span class="keyword">SELECT</span> date_add(date_add(str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">interval</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>) <span class="keyword">as</span> todayEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>12 最近12周 Last twelve weeks</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(date_sub(curdate(), <span class="type">interval</span> <span class="number">12</span> week),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> lastTwelveWeeksBegin;</span><br><span class="line"><span class="keyword">SELECT</span> date_add(date_add(str_to_date(curdate(),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">interval</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>) <span class="keyword">as</span> todayEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>最近3月 Last three month</p>
<p>``sql<br>SELECT str_to_date(date_sub(curdate(), interval 3 month),’%Y-%m-%d %H:%i:%s’) as lastThreeMonthBegin;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">- 未来3天 Three day later</span><br><span class="line"></span><br><span class="line">  &#96;&#96;&#96;sql</span><br><span class="line">  SELECT str_to_date(date_sub(curdate(), interval -3 day),&#39;%Y-%m-%d %H:%i:%s&#39;) as threeDaysLaterEnd;</span><br></pre></td></tr></table></figure></li>
<li><p>未来3月 Three months later</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(date_sub(curdate(), <span class="type">interval</span> <span class="number">-3</span> <span class="keyword">month</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>) <span class="keyword">as</span> threeMonthsLaterEnd; </span><br></pre></td></tr></table></figure></li>
<li><p>取一天的开始时间</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> str_to_date(DATE_FORMAT(<span class="string">&#x27;2018-03-03&#x27;</span>,<span class="string">&#x27;%Y-%m-%d&#x27;</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>);</span><br></pre></td></tr></table></figure></li>
<li><p>取第二天的开始时间</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DATE_ADD(str_to_date(DATE_FORMAT(NOW(),<span class="string">&#x27;%Y-%m-%d&#x27;</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">INTERVAL</span> <span class="number">1</span> <span class="keyword">DAY</span>);</span><br><span class="line"><span class="keyword">select</span> DATE_ADD(str_to_date(DATE_FORMAT(<span class="string">&#x27;2018-03-03&#x27;</span>,<span class="string">&#x27;%Y-%m-%d&#x27;</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">INTERVAL</span> <span class="number">1</span> <span class="keyword">DAY</span>);</span><br></pre></td></tr></table></figure></li>
<li><p>取一天的结束时间</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> DATE_ADD(DATE_ADD(str_to_date(DATE_FORMAT(NOW(),<span class="string">&#x27;%Y-%m-%d&#x27;</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">INTERVAL</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>);</span><br><span class="line"><span class="keyword">select</span> DATE_ADD(DATE_ADD(str_to_date(DATE_FORMAT(<span class="string">&#x27;2018-03-03&#x27;</span>,<span class="string">&#x27;%Y-%m-%d&#x27;</span>),<span class="string">&#x27;%Y-%m-%d %H:%i:%s&#x27;</span>),<span class="type">INTERVAL</span> <span class="number">1</span> <span class="keyword">DAY</span>),<span class="type">INTERVAL</span> <span class="number">-1</span> <span class="keyword">SECOND</span>);</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/09/12/springboot%E4%BD%BF%E7%94%A8rabbitmq/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/09/12/springboot%E4%BD%BF%E7%94%A8rabbitmq/" class="post-title-link" itemprop="url">springboot使用rabbitmq</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-09-12 14:03:42" itemprop="dateCreated datePublished" datetime="2019-09-12T14:03:42+08:00">2019-09-12</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/amqp/" itemprop="url" rel="index"><span itemprop="name">amqp</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="Message-Broker与AMQP简介"><a href="#Message-Broker与AMQP简介" class="headerlink" title="Message Broker与AMQP简介"></a>Message Broker与AMQP简介</h2><p>Message Broker是一种消息验证、传输、路由的架构模式，其设计目标主要应用于下面这些场景：</p>
<ul>
<li>消息路由到一个或多个目的地</li>
<li>消息转化为其他的表现方式</li>
<li>执行消息的聚集、消息的分解，并将结果发送到他们的目的地，然后重新组合相应返回给消息用户</li>
<li>调用Web服务来检索数据</li>
<li>响应事件或错误</li>
<li>使用发布-订阅模式来提供内容或基于主题的消息路由</li>
</ul>
<p>AMQP是Advanced Message Queuing Protocol的简称，它是一个面向消息中间件的开放式标准应用层协议。AMQP定义了这些特性：</p>
<ul>
<li>消息方向</li>
<li>消息队列</li>
<li>消息路由（包括：点到点和发布-订阅模式）</li>
<li>可靠性</li>
<li>安全性</li>
</ul>
<h3 id="RabbitMQ"><a href="#RabbitMQ" class="headerlink" title="RabbitMQ"></a>RabbitMQ</h3><p>RabbitMQ就是以AMQP协议实现的一种中间件产品，它可以支持多种操作系统，多种编程语言，几乎可以覆盖所有主流的企业级技术平台。</p>
<h4 id="ubuntu-安装"><a href="#ubuntu-安装" class="headerlink" title="ubuntu 安装"></a>ubuntu 安装</h4><p>在Ubuntu中，我们可以使用APT仓库来进行安装</p>
<ol>
<li><p>安装Erlang，执行：<code>apt-get install erlang</code></p>
</li>
<li><p>执行下面的命令，新增APT仓库到 <code>/etc/apt/sources.list.</code></p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;deb http://www.rabbitmq.com/debian/ testing main&#x27;</span> | sudo tee /etc/apt/sources.list.d/rabbitmq.list</span><br></pre></td></tr></table></figure></li>
<li><p>更新APT仓库的package list，执行 <code>sudo apt-get update</code> 命令</p>
</li>
<li><p>安装Rabbit Server，执行 <code>sudo apt-get install rabbitmq-server</code> 命令</p>
</li>
<li><p>开启Web管理插件</p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rabbitmq-plugins <span class="built_in">enable</span> rabbitmq_management</span><br></pre></td></tr></table></figure></li>
</ol>
<h4 id="docker-安装"><a href="#docker-安装" class="headerlink" title="docker 安装"></a>docker 安装</h4><ol>
<li><p>查找镜像</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search rabbitmq</span><br></pre></td></tr></table></figure></li>
<li><p>拉取镜像</p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull rabbitmq</span><br></pre></td></tr></table></figure></li>
<li><p>启动镜像</p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --name rabbitmq --hostname=my_rabbitmq rabbitmq:latest</span><br></pre></td></tr></table></figure>

<p> 参数解释：</p>
<ul>
<li>–hostname：指定容器主机名称</li>
<li>–name:指定容器名称</li>
<li>-p:将mq端口号映射到本地</li>
<li>15672 ：表示 RabbitMQ 控制台端口号，可以在浏览器中通过控制台来执行 RabbitMQ 的相关操作。</li>
<li>5672 : 表示 RabbitMQ 所监听的 TCP 端口号，应用程序可通过该端口与 RabbitMQ 建立 TCP 连接，完成后续的异步消息通信</li>
<li>RABBITMQ_DEFAULT_USER：用于设置登陆控制台的用户名，设置为 <code>admin</code>, 默认是 <code>guest</code></li>
<li>RABBITMQ_DEFAULT_PASS：用于设置登陆控制台的密码，设置为 <code>admin</code>, 默认是 <code>guest</code></li>
</ul>
<p> 容器启动成功后，可以在浏览器输入地址：<a target="_blank" rel="noopener" href="http://localhost:15672/">http://localhost:15672/</a></p>
<p> ps：RabbitMQ出于安全的考虑，默认是只能访问localhost:15762访问的，如果想用其他ip，是需要自己配置的。</p>
</li>
</ol>
<h4 id="WEB-界面"><a href="#WEB-界面" class="headerlink" title="WEB 界面"></a>WEB 界面</h4><p><img src="/images/rabbitmqserver_web.png" alt="rabbitmqserver_web.png"></p>
<h3 id="rabbitmq-介绍"><a href="#rabbitmq-介绍" class="headerlink" title="rabbitmq 介绍"></a>rabbitmq 介绍</h3><h3 id="spring-boot-集成-RabbitMQ"><a href="#spring-boot-集成-RabbitMQ" class="headerlink" title="spring boot 集成 RabbitMQ"></a>spring boot 集成 RabbitMQ</h3><ol>
<li><p>maven 依赖</p>
 <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-amqp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p>配置文件</p>
 <figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">spring-boot-rabbitmq</span></span><br><span class="line">  <span class="attr">rabbitmq:</span></span><br><span class="line">    <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">5672</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">guest</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">guest</span></span><br></pre></td></tr></table></figure></li>
<li><p>简单发送字符串</p>
<ol>
<li>定义队列</li>
</ol>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.amqp.core.Queue;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> fengxuechao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 0.1</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/9/12</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RabbitConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Queue <span class="title">queueHello</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Queue(<span class="string">&quot;hello&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Queue <span class="title">queueObject</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Queue(<span class="string">&quot;object&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>定义发送者</li>
</ol>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.amqp.core.AmqpTemplate;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.time.LocalDateTime;</span><br><span class="line"><span class="keyword">import</span> java.time.format.DateTimeFormatter;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> fengxuechao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 0.1</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/9/12</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloSender</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> AmqpTemplate rabbitTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">send</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;</span><br><span class="line">        String context = <span class="string">&quot;hello &quot;</span> + LocalDateTime.now().format(DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy-MM-dd HH:mm:ss.SSS&quot;</span>)) + <span class="string">&quot;:&quot;</span> + i;</span><br><span class="line">        System.out.println(<span class="string">&quot;Sender : &quot;</span> + context);</span><br><span class="line">        <span class="keyword">this</span>.rabbitTemplate.convertAndSend(<span class="string">&quot;hello&quot;</span>, context);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>定义接收者</li>
</ol>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.amqp.rabbit.annotation.RabbitHandler;</span><br><span class="line"><span class="keyword">import</span> org.springframework.amqp.rabbit.annotation.RabbitListener;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> fengxuechao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 0.1</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/9/12</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@RabbitListener(queues = &quot;hello&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloReceiver2</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RabbitHandler</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">process</span><span class="params">(String hello)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Receiver 2 : &quot;</span> + hello);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>测试</li>
</ol>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"><span class="keyword">import</span> org.junit.runner.RunWith;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.annotation.Repeat;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.context.junit4.SpringRunner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.junit.Assert.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> fengxuechao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 0.1</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/9/12</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RunWith(SpringRunner.class)</span></span><br><span class="line"><span class="meta">@SpringBootTest</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloSenderTest</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> HelloSender sender;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">send</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">10</span>;i++)&#123;</span><br><span class="line">            sender.send(i);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 控制台打印结果</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:0</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:1</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:2</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:3</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:4</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:5</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:6</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:7</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:8</span><br><span class="line">Receiver 2 : hello 2019-09-12 17:27:42.744:9</span><br></pre></td></tr></table></figure></li>
<li><p>发送对象</p>
<p> Spring Boot 完美的支持对象的发送和接收，不需要额外的配置。</p>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> Queue <span class="title">queueObject</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> Queue(<span class="string">&quot;object&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@RabbitListener(queues = &quot;object&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ObjectReceiver</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RabbitHandler</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">process</span><span class="params">(User user)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Receiver object : &quot;</span> + user);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ObjectSender</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> AmqpTemplate rabbitTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">send</span><span class="params">(User user)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Sender object: &quot;</span> + user.toString());</span><br><span class="line">        <span class="keyword">this</span>.rabbitTemplate.convertAndSend(<span class="string">&quot;object&quot;</span>, user);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 结果如下：</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Sender object: User&#123;name&#x3D;&#39;neo&#39;, pass&#x3D;&#39;123456&#39;&#125;</span><br><span class="line">Receiver object : User&#123;name&#x3D;&#39;neo&#39;, pass&#x3D;&#39;123456&#39;&#125;</span><br></pre></td></tr></table></figure></li>
<li></li>
</ol>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/12/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/12/">12</a><span class="page-number current">13</span><a class="page-number" href="/blog/page/14/">14</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/19/">19</a><a class="extend next" rel="next" href="/blog/page/14/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>


<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/blog/js/utils.js"></script><script src="/blog/js/motion.js"></script><script src="/blog/js/schemes/muse.js"></script><script src="/blog/js/next-boot.js"></script>

  
<script src="/blog/js/local-search.js"></script>






  





</body>
</html>
